package com.xingzhi.shortvideosharingplatform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xingzhi.shortvideosharingplatform.model.Comment;
import com.xingzhi.shortvideosharingplatform.model.Users;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CommentMapper extends BaseMapper<Comment> {
    
    @Update("UPDATE video SET comment_count = comment_count + #{increment} WHERE id = #{videoId}")
    int updateVideoCommentCount(@Param("videoId") Long videoId, @Param("increment") int increment);
    
    @Update("UPDATE user_profiles SET comment_count = comment_count + #{increment} WHERE user_id = #{userId}")
    int updateUserCommentCount(@Param("userId") Long userId, @Param("increment") int increment);
    
    /**
     * 根据用户ID列表批量查询用户信息
     * @param userIds 用户ID列表
     * @return 用户信息列表
     */
    List<Users> selectUsersByIds(@Param("userIds") List<Long> userIds);
    
    /**
     * 增加评论的赞数
     * @param commentId 评论ID
     * @return 影响的行数
     */
    @Update("UPDATE comment SET like_count = like_count + 1 WHERE id = #{commentId}")
    int incrementLikeCount(@Param("commentId") Long commentId);
    
    /**
     * 减少评论的赞数
     * @param commentId 评论ID
     * @return 影响的行数
     */
    @Update("UPDATE comment SET like_count = like_count - 1 WHERE id = #{commentId} AND like_count > 0")
    int decrementLikeCount(@Param("commentId") Long commentId);
} 